<template>
  <div>
    <!-- 按钮 -->
    <div class="btns">
      <el-button type="primary" @click="toPublishHospital">增加定点医院</el-button>
    </div>
    <!-- / 按钮结束 -->
    <!-- 表格 -->
    <el-table :data="hospitals.list">
      <el-table-column label="序号" type="index" :index="1"></el-table-column>
      <el-table-column label="医院名称" prop="name"></el-table-column>
      <el-table-column label="医院介绍" prop="introduce"></el-table-column>
      <el-table-column label="医院电话" prop="phone"></el-table-column>
      <el-table-column label="医院地址">
        <template slot-scope="scope">
          {{scope.row.province}} {{scope.row.city}} {{scope.row.area}} {{scope.row.address}}  
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="toDelete(scope.row)">删除</el-button>
          <el-button size="mini" type="text" @click="toEdit(scope.row)">修改</el-button>
          <el-button size="mini" type="text" @click="toLocation(scope.row)">定位</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <el-pagination
      layout="prev, pager, next"
      @current-change="currentChange"
      :current-page="hospitals.page"
      :page-size="hospitals.pageSize"
      :total="hospitals.total">
    </el-pagination>

    <!-- /分页组件 -->
  </div>
</template>
<script>
import {get} from '@/utils/request'
export default {
  data(){
    return {
      hospitals:{ list:[] },
      param:{
        page:1,
        pageSize:10
      }
    }
  },
  mounted(){
    this.loadHospitals();
  },
  methods:{
    // 当前页发生变化
    currentChange(page){
      this.param.page = page;
      this.loadHospitals();
    },

    // 去定位
    toLocation(row) {
      // 跳转到资讯发布页面
      this.$router.push({
        path:'/hospital/location',
        query:row     // 携带参数
      })
    },
    // 去编辑
    toEdit(row){
      // 跳转到资讯发布页面
      this.$router.push({
        path:'/hospital/create',
        query:row     // 携带参数
      })
    },
    // 去删除
    toDelete(row){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let url = "http://121.199.29.84:8002/hospital/deleteById"
          get(url,{id:row.id}).then(resp => {
            // 提示删除成功
            this.$message({type:"success",message:resp.message})
            // 加载文章数据
            this.loadHospitals();
          })
        })
    },
    // 去发布资讯
    toPublishHospital(){
      // 跳转到资讯发布页面
      this.$router.push({
        path:'/hospital/create'
      })
    },
    loadHospitals(){
      let url = "http://121.199.29.84:8002/hospital/pageQuery";
      get(url,this.param).then(resp => {
        this.hospitals = resp.data;
      })
    }
  }
}
</script>
<style scoped>

</style>